﻿//卡号管理 初始化
function initPage() {

	 
	$('div.c_right').tabs({
		containerClass: "c_r_body",
		selectedClass: "on",
		hash: true
	});
	//查询信息列表
	$('#scform').submit(function(){
		loadRsList("1");//分页查询	
		return false;
	});
	/*输入框信息校验
	$("#card_Validate").keyup(function(){
		var v = this.value.replace(/[^\d]/g, '').toInt();
		var c = $('#credit').text().toInt();
		if (v > c) v = c;
		rate = $('#rate').val().toInt();
		this.value = v;
		$('#point').html(v*rate+'');
	});*/
	//添加信息动作
	$('#form_card_add').submit(function(){
		var form = $(this);
		var msg = $("#result");
		var data = form.serializeArray();
		msg.warning(TXT_POSTDATA);
		form.disabled();
		$.ajax({
			type: "POST",
			url: form.attr("action")+"?act=add",
			data: data,
			dataType: "json",
			success: function(ret){
				msg.warning(ret.msg);		
				if (ret.success) {
					var d = ret.url ? ret.url : "/";
					setTimeout( function() {									
						window.location = d;
					}, 800)
				} else {
					form.enabled();
				}				
			},
			error: function(res){
				alert("error");
				msg.warning(TXT_NETBUSY);
				form.enabled();
			}
		});
		return false;
	});
}
//批量生成卡号 初始化
function initPage_Make() {
		//查询信息列表  导出列表查询
	$('#scform').submit(function(){
		loadRsList("1");//分页查询	
		return false;
	});
	 ///批量制卡
	$('div.c_right').tabs({
		containerClass: "c_r_body",
		selectedClass: "on",
		hash: true
	});
	//添加信息动作
	$('#form_card_make').submit(function(){
		var form = $(this);
		var msg = $("#result");
		var data = form.serializeArray();
		msg.warning(TXT_POSTDATA);
		form.disabled();
		$.ajax({
			type: "POST",
			url: form.attr("action")+"?act=make",
			data: data,
			dataType: "json",
			success: function(ret){
				msg.warning(ret.msg);		
				if (ret.success) {
					var d = ret.url ? ret.url : "/";
					setTimeout( function() {									
						window.location = d;
					}, 800)
				} else {
					setTimeout( function() {									
						msg.warning('');		
						form.enabled();
					}, 800)
				}				
			},
			error: function(res){								
				msg.warning(TXT_NETBUSY);
				form.enabled();
			}
		});
		return false;
	});
}
//填充json数据
function loadObjRsList(data) {	
	//将action返回的json放入临时div_load_temp中保存
	$("#div_load_json_temp").html(TXT_NETWAIT).load($("#scform").attr("action")+"", data, function() { 
		//执行js，将json字串 生成 obj_json_data对象
		eval(" var obj_json_data ="+$("#div_load_json_temp").html()+";"); 
		//将trimpath生成的html，放入显示div中div_rslist
		$('#div_rslist').html(TrimPath.processDOMTemplate("template_jst", obj_json_data));
	});   
}

//翻页 查询某页的记录
function loadRsList(page) {	
		$("#page").val(page);
		var data =$("#scform").serializeArray();
		loadObjRsList(data);	
}

//按照卡号删除
function rs_el_Delete(a) {
	if (!a) {
	 	a = [];
		$("#scform :checkbox[name='id_all']:enabled:checked").each(
				function() { 
					a.push(this.value)
				});
		a = a.join(",")
	} 
	if (!a) {
		return alert("请选择要删除的记录")
	}
	if (!confirm("确定要删除所选记录？")) {
		return
	}
	form = $("#scform");
	form.disabled();
	$.ajax( {
		type :"POST",
		url :form.attr("action")+"",
		data : {
			act :"delete",
			id :a
		},
		dataType :"json",
		success : function(b) {
			if (b.success) {
					setTimeout( function() {
						window.location =b.url ? b.url : "/";// "card_manage.asp";
					}, 300)
			} else {
				alert(b.msg);
				form.enabled();
			}
		},
		error : function(b) {
			alert(TXT_NETBUSY);
			form.enabled()
		}
	})
};
//按照批次编码删除
function rs_el_Del_batch(a) {
	if (!a) {
	 	a = [];
		$("#scform :checkbox[name='id_all']:enabled:checked").each(
				function() { 
					a.push(this.value)
				});
		a = a.join(",")
	} 
	if (!a) {
		return alert("请选择要删除的记录")
	}
	if (!confirm("确定要删除所选记录？")) {
		return
	}
	form = $("#scform");
	form.disabled();
	$.ajax( {
		type :"POST",
		url :form.attr("action")+"",
		data : {
			act :"deletebatchcode",
			id :a
		},
		dataType :"json",
		success : function(b) {
			if (b.success) {
					setTimeout( function() {
						window.location =b.url ? b.url : "/";// "card_make.asp";
					}, 300)
			} else {
				alert(b.msg);
				form.enabled();
			}
		},
		error : function(b) {
			alert(TXT_NETBUSY);
			form.enabled()
		}
	})
};
 